/**
 * @file 订单详情-百度地图
 * @author sunlife
 * @date 2020/08/17 19:03:40
 */

layui.extend({
    oms_work_config: "work/config/zmn.oms.work.config"
}).define(['layer', 'form', 'NP', 'laytpl', 'table', 'zmnUtils', 'Vue', '$http', 'oms_work_config'], function (exports) {
    let $ = layui.$;
    let table = layui.table;
    let zmnUtils = layui.zmnUtils;
    var config = layui.oms_work_config;

    // 表头
    const newWorkCols = [[
        {field: 'orderId', hide: true},
        {field: 'workId', hide: true},
        {field: 'receiveTime', title: '下单时间', align: 'center', width: 200},
        {field: 'productInfo', title: '服务信息', align: 'center'},
        {field: 'totalAmount', title: '金额', align: 'center',templet: e => zmnUtils.unit.fenToYuan(e.totalAmount)},
        {field: 'channelName', title: '下单渠道', align: 'center'},
        {field: 'statusName', title: '状态', align: 'center'},
        {field: 'resultStatusName', title: '结果', align: 'center'},
        {field: 'opt', title: '操作', align: 'center', templet: '#btn-operator'}
    ]];
    const reworkWorkCols = [[
        {field: 'orderId', hide: true, align: 'center', width: 200},
        {field: 'workId', hide: true, align: 'center', width: 200},
        {field: 'receiveTime', title: '下单时间', align: 'center', width: 200},
        {field: 'productInfo', title: '服务信息', align: 'center'},
        {field: 'totalAmount', title: '金额', align: 'center',templet: e => zmnUtils.unit.fenToYuan(e.totalAmount)},
        {field: 'channelName', title: '下单渠道', align: 'center'},
        {field: 'statusName', title: '状态', align: 'center'},
        {field: 'resultStatusName', title: '结果', align: 'center'},
        {field: 'opt', title: '操作', align: 'center', templet: '#btn-operator'}
    ]];
    const refundWorkCols = [[
        {field: 'orderId', hide: true, align: 'center', width: 200},
        {field: 'workId', hide: true, align: 'center', width: 200},
        {field: 'receiveTime', title: '退款时间', align: 'center', width: 200},
        {field: 'productInfo', title: '服务信息', align: 'center'},
        {field: 'totalAmount', title: '金额', align: 'center',templet: e => zmnUtils.unit.fenToYuan(e.totalAmount)},
        {field: 'channelName', title: '下单渠道', align: 'center'},
        {field: 'statusName', title: '状态', align: 'center'},
        {field: 'resultStatusName', title: '结果', align: 'center'},
        {field: 'refundReviewStatusName', title: '审核结果', align: 'center'},
        {field: 'opt', title: '操作', align: 'center', templet: '#btn-operator'}
    ]];

    const compensateWorkCols = [[
        {field: 'orderId', hide: true, align: 'center', width: 200},
        {field: 'workId', hide: true, align: 'center', width: 200},
        {field: 'receiveTime', title: '下单时间', align: 'center', width: 200},
        {field: 'productInfo', title: '服务信息', align: 'center'},
        {field: 'totalAmount', title: '金额', align: 'center',templet: e => zmnUtils.unit.fenToYuan(e.totalAmount)},
        {field: 'statusName', title: '状态', align: 'center'},
        {field: 'resultStatusName', title: '结果', align: 'center'},
        {field: 'refundReviewStatusName', title: '审核结果', align: 'center'},
        {field: 'opt', title: '操作', align: 'center', templet: '#btn-operator'}
    ]];

    /**
     * 获取当前 URL 的查询参数
     * @returns {Object}
     * @private
     */
    function _getQueryParams (url) {
        var r = url ? url.split('?')[1] : window.location.search.substr(1);
        var params = {};
        if (r && r.length) {
            var arr = r.split('&');
            arr.forEach((item) => {
                var ar = item.split('=');
                params[decodeURIComponent(ar[0])] = decodeURIComponent(ar[1]);
            });
        }

        return params;
    }


    /**
     * 初始化页面
     */
    function initPage () {
        // 数据转化
        let workList = JSON.parse(workListStr);

        let cols;
        switch (type) {
            case "2":
                cols = reworkWorkCols;
                break;
            case 3:
                cols = refundWorkCols;
                break;
            case 4:
                cols = compensateWorkCols;
                break;
            default:
                cols = newWorkCols;
        }
        // 多师傅算账
        table.render({
            elem: '#orderlist',
            cols: cols,
            data: workList,
            limit: 10000
        });

        table.on('tool(orderlist-table)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if(layEvent === 'detail'){ //查看
                var params = {
                    orderId: data.orderId,
                    workId: data.workId
                };
                parent.reloadDetail(params);
            }
        });

    }

    /**
     * 初始化页面事件
     */
    function initEvent () {
        // 地图关闭按钮点击事件
    }

    /**
     * 程序入口
     */
    function init () {
        initPage();
        initEvent();
    }

    init();
    exports('oms_work_subworklist');
});




